package com.lijian.netty.nio6;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @author lj02
 * @desc 传统 io 如何转换为nio  FileOutputStream
 * @date 2018/12/1
 */
public class NioTest3 {


    public static void main(String[] args) throws Exception {


        FileOutputStream fileOutputStream = new FileOutputStream("niotest3.txt");

        FileChannel channel = fileOutputStream.getChannel();

        ByteBuffer buf = ByteBuffer.allocate(512);

        byte[] msg = "this is hello world ! ".getBytes();

        for (byte m : msg) {
            buf.put(m);
        }
        buf.flip();

        channel.write(buf);
        System.out.println();
        fileOutputStream.close();


    }
}
